<?php
namespace frontend\widget;


/*
**Team :
**Coding by 曾钰媛 1511240 170706
**This is the article list widget
*/

use yii\base\Widget;
use Yii;
use common\models\PreAdminArticle;
use frontend\models\PostForm;
use yii\helpers\Url;

class postWidget extends Widget
{
	public $title='';
	
	public $limit=6;
	
	public $more=true;
	
	public $page=false;
	
	public function run()
	{
		$curPage=Yii::$app->request->get('page',1);
		$cond=['=','status',1];
		$res =PostForm::getList($cond,$curPage,$this->limit);
		$result['title']=$this->title?:"最新文章";
		$result['more']=Url::to(['pre-admin-article/index']);
		$result['body']=$res['data']?:[];
		
		if($this->page){
			$page= new Pagination(['totalCount'=>$res['count'],'pageSize'=>$res['pageSize']]);
			$result['page']=$page;
		}
		return $this->render('listindex',['data'=>$result]);
	}
	
}